//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Controls;


namespace OpenLS.Spreadsheet.UI
{
    partial class CustomFiltersResources
    {
        public CustomFiltersResources()
        {
            InitializeComponent();
        }
        void OnComboLoaded(object sender, object args)
        {
            ComboBox cb = (ComboBox)sender;
            cb.ItemsSource = PossibleFilters.Items;
            CustomFilters cf = ((CustomFilters)cb.DataContext);
            if (cb.Name == "first")
                cb.SelectedItem = cf.First.Operator;
            else if (cf.Second != null)
                cb.SelectedItem = cf.Second.Operator;
        }
        void OnSelectionChanged(object sender, object args)
        {
            ComboBox cb = (ComboBox)sender;
            CustomFilters cf = ((CustomFilters)cb.DataContext);
            if (cb.Name == "first")
            {
                if (!(cb.SelectedItem is FilterOperator))
                {
                    cf.First = null;
                    return;
                }
                if (cf.First == null)
                    cf.First = new CustomFilter();
                FilterOperator op = (FilterOperator)cb.SelectedItem;
                cf.First.Operator = op;
            }
            else
            {
                if (!(cb.SelectedItem is FilterOperator))
                {
                    cf.Second = null;
                    return;
                }
                if (cf.Second == null)
                    cf.Second = new CustomFilter();
                FilterOperator op = (FilterOperator)cb.SelectedItem;
                cf.Second.Operator = op;
            }
        }


    }
}
